package cn.edu.neusoft.wuguangsheng.market.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.market.activity.FoodByIdActivity;
import cn.edu.neusoft.wuguangsheng.market.bean.FoodByShopBean;

/**
 * Created by little on 2018/4/22.
 */

public class SearchAdapter extends BaseAdapter<FoodByShopBean> {
    public SearchAdapter(Context context, List<FoodByShopBean> items, int layoutResource){
        super(context, items, layoutResource);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(context)
                .inflate(layoutResourse,parent,false);
        SearchViewHolder cartViewHolder=new SearchViewHolder(itemView);
        return cartViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        SearchViewHolder myViewHolder=(SearchViewHolder) holder;
        //AllCommentBean allCommentBean=items.get(position);
        FoodByShopBean foodByShopBean=items.get(position);
        final String fname=foodByShopBean.getFoodname();
        myViewHolder.se_name.setText(fname);
        final double p=foodByShopBean.getPrice();
        final String price=String.valueOf(p);
        myViewHolder.se_price.setText("￥"+price);
        final String intro=foodByShopBean.getIntro();
        myViewHolder.se_intro.setText(intro);
        final String pic=foodByShopBean.getPic();
        final String mrid=foodByShopBean.getMrid();
        final String fid=foodByShopBean.getFid();

        //final String foodprice=foodByShopBean.getPrice();
        //myViewHolder.tv_card3.setText(pic);
        Picasso.with(context).load(items.get(position).getPic()).resize(90,50).centerCrop().into(myViewHolder.se_img);
        myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent=new Intent(context, FoodByIdActivity.class);
                intent.putExtra("fid",fid);
                intent.putExtra("fname",fname);
                //intent.putExtra("price",price);
                intent.putExtra("price",price);
                intent.putExtra("intro",intro);
                intent.putExtra("pic",pic);
                intent.putExtra("mrid",mrid);
                context.startActivity(intent);
            }
        });

    }
}
